//
//  MainTableViewController.swift
//  Sina
//
//  Created by 王杰 on 15/11/8.
//  Copyright © 2015年 王杰. All rights reserved.
//

import UIKit

class MainTableViewController: UITabBarController {

    @objc private func composeDidClick() {
    
//    print(__FUNCTION__)

        let compose = ComposeViewController()
        
        let nav = UINavigationController(rootViewController: compose)
        presentViewController(nav, animated: true, completion: nil)
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        let mainTabBar = MainTabBar()
       
        setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewControllers()
        
       print(tabBar.classForCoder)
        
        mainTabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
    
    }

    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        

    }

    
    private func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        //设置自带的颜色出去系统的影响
       self.tabBar.tintColor = UIColor.orangeColor()
        
//        let nav = UINavigationController(rootViewController: vc)
            let nav = BaseNavViewController(rootViewController: vc)
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
    }
    
}
